Automatic Deployments: Install CodeDeploy Agent on EC2

We will be installing CodeDeploy agent on our EC2 instance in this lesson.

Objective#

  • Automatically update our application when a change gets pushed to GitHub.

Steps#

  • Install the CodeDeploy agent on our EC2 instance.

The deployment pipeline#

Now it’s time to create the deployment pipeline in CloudFormation. Let’s start by setting up a few environment variables in our deploy-infra.sh script with information about our GitHub credentials.

deploy-infra.sh

And then we can pass these variables to our main.yml script as parameters.

deploy-infra.sh

To do that, we also need to update the Parameters section in main.yml to receive the GitHub information.

main.yml

Next, we need to add a new managed policy to allow our EC2 instance to access CodeDeploy.

main.yml

Line #14: Allows our EC2 instance to access CodeDeploy.

We also need to create a new IAM role to allow the CodeBuild, CodeDeploy, and CodePipeline services to access our AWS resources.

main.yml

Then we can define our CodeBuild project.

main.yml

Next, we can define our CodeDeploy application. This lets CodeDeploy know that our deployment target is EC2.

main.yml

Line #5: In this case, Server means EC2.

To complete the CodeDeploy setup, we also need to define a deployment group. For now, we’re going to have one deployment group called Staging. This will be our pre-production environment. We will add another deployment group for production when we get to the Production section.

main.yml

Line #7: For pre-production, we can choose to deploy as fast as possible. We’ll do this differently in production.

Line #9: These filters define how CodeDeploy will find the EC2 instances to deploy to.


And finally, we just need to define our pipeline. Let’s do that in the next lesson.

Automatic Deployments: CodeBuild
Automatic Deployments: Create a CodePipeline
Mark as Completed
Report an Issue